# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=procps-ng
pkgver=4.0.4
pkgrel=2
pkgdesc="Utilities for monitoring your system and processes on your system"
url="https://gitlab.com/procps-ng/procps"
arch="all"
license="GPL-2.0-or-later AND LGPL-2.1-or-later"
makedepends="
	autoconf
	automake
	gettext-dev
	libtool
	ncurses-dev
	"
checkdepends="dejagnu"
subpackages="$pkgname-dev $pkgname-doc $pkgname-lang libproc2"
source="$pkgname-$pkgver.tar.xz::https://sourceforge.net/projects/procps-ng/files/Production/procps-ng-$pkgver.tar.xz/download
	disable-test_pids-check.patch
	"

# used to be named procps
provides="procps=$pkgver-r$pkgrel"
replaces="procps"

case "$CARCH" in
x86|ppc64le)
	# TODO, x86: FAIL: strtod_nol_or_err("123") != 123.000000
	# https://gitlab.com/procps-ng/procps/-/issues/271
	# ppc64le: FAIL: check_fatal_proc_unmounted
	options="$options !check"
	;;
esac

# secfixes:
#   4.0.4-r0:
#     - CVE-2023-4016
prepare() {
	default_prepare
	autoreconf -vif
}

build() {
	export LIBS="$LIBS -lintl"
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--bindir=/bin \
		--sbindir=/sbin \
		--mandir=/usr/share/man \
		--sysconfdir=/etc \
		--localstatedir=/var \
		--docdir=/usr/share/doc/procps \
		--datarootdir=/usr/share \
		--disable-static \
		--disable-w-from \
		--disable-kill \
		--disable-rpath \
		--with-ncurses \
		--disable-modern-top
	make
}

check() {
	make check || {
		cat test-suite.log
		return 1
	}
}

package() {
	make DESTDIR="$pkgdir" ldconfig=true install="install -D" \
		install

	# These binaries are identical.
	ln -sf pgrep "$pkgdir"/bin/pkill

	# Override BusyBox symlinks
	mkdir -p "$pkgdir"/usr/bin
	for i in free pgrep pkill pmap pwdx top uptime; do
		mv "$pkgdir"/bin/$i "$pkgdir"/usr/bin/$i
	done
}

libproc2() {
	pkgdesc="Library for monitoring system and processes"

	amove usr/lib
}

sha512sums="
94375544e2422fefc23d7634063c49ef1be62394c46039444f85e6d2e87e45cfadc33accba5ca43c96897b4295bfb0f88d55a30204598ddb26ef66f0420cefb4  procps-ng-4.0.4.tar.xz
de97f76465ecb3f4a118a809111039a461070cd585073ee49ee76c105568f0caf5fc5a66ba049193ccb01bd18326ec1f6feb668c90df1cdbd9e1fb2ad4d77dd3  disable-test_pids-check.patch
"
